#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
void Create_a_txt(const char * file1)
{
        ofstream out_file(file1,ios::out);
        if(!out_file)
        {
                cout<<"file error"<<endl;
                return;
        }
        out_file<<"how are you today?"<<endl;
        out_file<<"i'm fine thank you and you?"<<endl;
	out_file<<"i'm not so fine"<<endl;
	out_file<<"i think you need to have a rest"<<endl;
	out_file<<"thank you"<<endl;
        out_file.close();
        return;
}
void print_a_txt(const char *file)
{
        ifstream out_file(file);
        string temp;
        while(getline(out_file,temp))
        {
                cout<<temp<<endl;
        }
        out_file.close();
}
void search_the_word(const char * file,const char * word)
{
	ifstream in_file(file);
	if(!in_file)
	{
		cout<<"file error"<<endl;
		return ;
	}
	string line;
	int line_num=0;
	int begin=-1;
	int count=0;
	while(getline(in_file,line))
	{
		++line_num;
		begin=-1;
		while((begin=line.find(word,begin+1))!=string::npos)
		{
			++count;
			cout<<"第"<<count<<"次："<<line_num<<"行  "<<begin<<"列"<<endl;
		}
	}
	cout<<"共"<<count<<"次"<<endl;
}
int main()
{
	const char * file="file_3.txt";
	const char * word="you";
	Create_a_txt(file);
	print_a_txt(file);

	search_the_word(file,word);
}


